//
//  tcsf/channel.h
//  Created by tommywang on 13-6-30.
//

#ifndef _tcsf_ndchannel_h_
#define _tcsf_ndchannel_h_

#include <string>
using namespace std;
#include "tdlexcept.h"
#include "net/btypes.h"
#include "sys/thread.h"
#include "sys/soloader.h"
#include "mem/rblock_queue.h"
using namespace tdl;
#include "sof.h"
using namespace tcsf;

namespace tcsf {
///////////////
template <typename Tsocket>
class ndchannel
{
public:
	typedef tdl::rblock_queue_ex<>				reqq_type;
	typedef tdl::soloader<tcsf::sofl_type>		soer_type;

public:
	Tsocket				lsocket;

	tdl::thread_pool	btp;

	reqq_type			req_q;

	soer_type			req_so;

public:
	ndchannel() {}

	ndchannel(const Tsocket& s) : lsocket(s) {}

	void build_req_queue(size_t qsize)
	{
		req_q.initialize(qsize);
	}

	void start_business_thread_pool(executor* e, size_t n, const std::string& sopath)
	{
		tdl_assert(e);

		req_so.initialize(sopath);
		req_so.load_sofunc<TCSF_SOF_ID_INIT>(TCSF_SOF_NAME_INIT);
		req_so.load_sofunc<TCSF_SOF_ID_DECODE>(TCSF_SOF_NAME_DECODE);
		req_so.load_sofunc<TCSF_SOF_ID_DOREQ>(TCSF_SOF_NAME_DOREQ);

		btp.run(n, e);
	}
};

////////////////////
}	// namespace tcsf
#endif

